package com.kehutong.payment.util;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.map.CaseInsensitiveMap;
import org.coraframework.util.Objects;

/**
 * Pay Http Response
 */
public class PayHttpResponse implements Serializable {

    private static final long serialVersionUID = 6322379661238027340L;

    private String body;
    private int status;
    private Map<String, List<String>> headers;

    public String getHeader(String name) {
        List<String> values = this.headerList(name);
        return Objects.isEmpty(values) ? null : values.get(0);
    }

    private List<String> headerList(String name) {
        if (Objects.isEmpty(name)) {
            return null;
        } else {
            CaseInsensitiveMap<String, List<String>> headersIgnoreCase = new CaseInsensitiveMap<>(getHeaders());
            return headersIgnoreCase.get(name.trim());
        }
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Map<String, List<String>> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, List<String>> headers) {
        this.headers = headers;
    }

    @Override
    public String toString() {
        return "PayHttpResponse{" +
            "body='" + body + '\'' +
            ", status=" + status +
            ", headers=" + headers +
            '}';
    }
}
